// <copyright file="LegacyUrl301Result.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

namespace CleverCMS.Core.Web.ActionResults
{
    using System.Web;
    using System.Web.Mvc;
    
    using Core.Extensions;

    public class LegacyUrl301Result : ActionResult
    {
        public LegacyUrl301Result(string redirectTo)
        {
            this.NewUrl = redirectTo;
        }

        public string NewUrl { get; private set; }

        public override void ExecuteResult(ControllerContext context)
        {
            HttpResponseBase response = context.RequestContext.HttpContext.Response;
            var httpContext = context.RequestContext.HttpContext;
            response.PermanentRedirect(Utils.GetBaseUrl(httpContext.Request.ApplicationPath, httpContext.Request.Url, true) + this.NewUrl);
        }
    }
}